<template>
  <td class="table-cell" :class="[customClass]" :colspan="widget.options.colspan || 1"
    :rowspan="widget.options.rowspan || 1"
    :style="{ width: widget.options.cellWidth + ' !important' || '', height: widget.options.cellHeight + ' !important' || '', 'word-break': !!widget.options.wordBreak ? 'break-all' : 'normal' }">
    <template v-for="(subWidget, swIdx) in widget.widgetList">
      <template v-if="'container' === subWidget.category">
        <component :is="getComponentByContainer(subWidget)" :widget="subWidget" :key="swIdx"
          :parent-list="widget.widgetList" :index-of-parent-list="swIdx" :parent-widget="widget"
          :sub-form-row-id="subFormRowId" :sub-form-row-index="subFormRowIndex" :sub-form-col-index="subFormColIndex">
          <!-- 递归传递插槽！！！ -->
          <template v-for="slot in Object.keys($slots)" v-slot:[slot]="scope">
            <slot :name="slot" v-bind="scope" />
          </template>
        </component>
      </template>
      <template v-else>
        <component :is="getFieldWidget(subWidget.type)" :field="subWidget" :key="swIdx" :parent-list="widget.widgetList"
          :index-of-parent-list="swIdx" :parent-widget="widget" :sub-form-row-id="subFormRowId"
          :sub-form-row-index="subFormRowIndex" :sub-form-col-index="subFormColIndex">
          <!-- 递归传递插槽！！！ -->
          <template v-for="slot in Object.keys($slots)" v-slot:[slot]="scope">
            <slot :name="slot" v-bind="scope" />
          </template>
        </component>
      </template>
    </template>
  </td>
</template>

<script>
import emitter from '@/utils/emitter'
import i18n from "../../../utils/i18n"
import refMixin from "../../../components/form-render/refMixin"
import FieldComponents from '@/components/form-designer/form-widget/field-widget/index'
import { SetDomStyle } from '@/utils/util'
export default {
  name: "TableCellItem",
  componentName: "ContainerItem",
  mixins: [emitter, i18n, refMixin],
  components: {
    ...FieldComponents,
  },
  props: {
    widget: Object,

    rowIndex: Number,
    colIndex: Number,

    subFormRowIndex: { /* 子表单组件行索引，从0开始计数 */
      type: Number,
      default: -1
    },
    subFormColIndex: { /* 子表单组件列索引，从0开始计数 */
      type: Number,
      default: -1
    },
    subFormRowId: { /* 子表单组件行Id，唯一id且不可变 */
      type: String,
      default: ''
    },
  },
  inject: ['refList', 'globalModel', 'isMixMode'],
  computed: {
    customClass() {
      return this.widget.options.customClass || ''
    },

  },
  created() {
    /* tableCell不生成组件引用，故无须调用initRefList！！ */
    //this.initRefList()
  },
  methods: {

  },
  mounted() {
    new SetDomStyle(this.$el, this.widget.options.comStyle).setStyle()
  }
}
</script>

<style lang="scss" scoped>
td.table-cell {
  display: table-cell;
  height: 36px;
  //border: 1px dashed #336699;
  // border: 1px solid #e5e5e5;
}
</style>
